<?php
/*
 * @version :  2013-4-24
 * @project :  account-system
 * @Author  :  Allen
 * @e-mail  :  shulei@maszy.cn
 */
 if(isset($_REQUEST['method'])){
 	if($_REQUEST['method']=="openswitch"){
 		file_put_contents("systemsetting.ini","recharge_switch=1");
 	}else if($_REQUEST['method']=="closeswitch"){
 		file_put_contents("systemsetting.ini","recharge_switch=0");
 	}
 }
 	$content = getXml();
 	outPutXml($content);


 //输出获得的值.
function get_ini_item($ini_items = null,$item_name = ''){//获得INI条目的值.
    if(empty($ini_items))
		return "";
  	else 
   		return $ini_items[$item_name];
}
function get_ini_file($file_name = "demo.ini"){
	 $str=file_get_contents($file_name);//读取ini文件存到一个字符串中.
	 $ini_list = explode("\r\n",$str);//按换行拆开,放到数组中.
	 $ini_items = array();
	 foreach($ini_list as $item){
	 	 $one_item = explode("=",$item);
	 	 if(isset($one_item[0])&&isset($one_item[1])) $ini_items[trim($one_item[0])] = trim($one_item[1]); //存成key=>value的形式.
	 }
	 return $ini_items;
}
function getXml(){
		$content = "";
		$content.= "<result>\n";
		$ini_items = get_ini_file("systemsetting.ini");
		$content.= "<recharge_switch>".get_ini_item($ini_items,'recharge_switch')."</recharge_switch>\n";
		$content.= "</result>\n";
	return $content;
}
function outPutXml($content) {
	header("Content-type:text/xml");
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n";
	echo "<netcuberesult>\n";
	echo $content;
	echo "</netcuberesult>";
	die();
}
die();
//如果要替换里面的东西就执行下面代码
$str=str_replace("要替换成的东西","替换成的东西",$str);
file_put_contents("systemsetting.ini",$str);//这是从新生成的PHP.ini文件
?>
